home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Dialectic 1.2 / source / Dialectic ƒ / Shell ƒ / environment.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  4.4 KB  |  123 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        environment.c
  4.  
  5. Purpose:    This module handles initializing the environment and
  6.             checking for various environmental characteristics.
  7.  
  8. \**********************************************************************/
  9.  
  10. #include "environment.h"
  11. #include "apple events.h"
  12. #include "error.h"
  13. #include "program globals.h"
  14. #include "GestaltEqu.h"
  15. #include "Traps.h"
  16.  
  17. Boolean            gHasColorQD;                /* color Quickdraw present? */
  18. Boolean            gHasAppleEvents;            /* apple events supported? */
  19. Boolean            gHasFSSpecs;                /* FSSpec calls supported? */
  20. Boolean            gStandardFile58;            /* standard file package supported? */
  21. Boolean            gHasPowerManager;            /* power manager present? (cf progress.c) */
  22. Boolean            gHasNotificationManager;    /* notification manager present? (cf error.c) */
  23. Boolean            gSystemSevenOrLater;        /* system 7 running? */
  24. Boolean            gWaitNextEventAvailable;    /* WaitNextEvent() implemented? */
  25. Boolean            gHasGestalt;                /* Gestalt() implemented? */
  26.  
  27. int                gForegroundWaitTime;        /* WaitNextEvent sleep time while in frgrnd */
  28. int                gBackgroundWaitTime;        /* WaitNextEvent sleep time while in bkgrnd */
  29. Boolean            gIsInBackground;            /* program is in background currently? */
  30. Boolean            gInProgress;                /* progress bar up? */
  31. Boolean            gDone;                        /* program done? */
  32. Boolean            gFrontWindowIsOurs;            /* frontmost window is one of ours? */
  33.  
  34. /* This is to stop the compiler from using Gestalt glue without killing
  35.    all the other pre-system 7 glue for other routines. */
  36. #pragma parameter __D0 RealGestalt(__D0,__A1)
  37. pascal OSErr RealGestalt(OSType selector,long *response) = {0xA1AD,0x2288};
  38. #define        Gestalt            RealGestalt
  39. #define        GESTALT_TRAP    0xA1AD            /* _Gestalt */
  40.  
  41. #define    GetTrapType(T)    (((T & 0x0800) > 0) ? ToolTrap : OSTrap)
  42. #define NumToolboxTraps()    ((NGetTrapAddress(_InitGraf, ToolTrap) ==    \
  43.                             NGetTrapAddress(0xAA6E, ToolTrap)) ? 0x0200    \
  44.                             : 0x0400)
  45.  
  46. Boolean TrapAvailable(int theTrap);
  47.  
  48. Boolean TrapAvailable(int theTrap)
  49. {
  50.     TrapType        tType;
  51.     
  52.     tType=GetTrapType(theTrap);
  53.     if (tType==ToolTrap)
  54.     {
  55.         theTrap=theTrap&0x07FF;
  56.         if (theTrap>=NumToolboxTraps())
  57.             theTrap=_Unimplemented;
  58.     }
  59.     return (NGetTrapAddress(theTrap, tType)!=NGetTrapAddress(_Unimplemented, ToolTrap));
  60. }
  61.  
  62. Boolean InitTheEnvironment(void)
  63. /* called very early -- this uses Gestalt to check out the computing environment;
  64.    see above for explanations of variables */
  65. {
  66.     long            gestalt_temp;
  67.     OSErr            isHuman;
  68.     SysEnvRec        theWorld;
  69.     
  70.     if (SysEnvirons(1, &theWorld)==envNotPresent)
  71.         return FALSE;
  72.     
  73.     gWaitNextEventAvailable=TrapAvailable(_WaitNextEvent);
  74.     gHasGestalt=TrapAvailable((int)GESTALT_TRAP);
  75.  
  76.     if (gHasGestalt)
  77.     {
  78.         isHuman=Gestalt(gestaltSystemVersion, &gestalt_temp);
  79.         gSystemSevenOrLater=!(isHuman || (gestalt_temp < 1792));
  80.         
  81.         isHuman=Gestalt(gestaltQuickdrawVersion, &gestalt_temp);
  82.         gHasColorQD=!(isHuman || (gestalt_temp < gestalt8BitQD));
  83.     
  84.         isHuman=Gestalt(gestaltFSAttr, &gestalt_temp);
  85.         gHasFSSpecs=((isHuman==noErr) && (gestalt_temp&(1<<gestaltHasFSSpecCalls)));
  86.     
  87.         isHuman=Gestalt(gestaltStandardFileAttr, &gestalt_temp);
  88.         gStandardFile58=((isHuman==noErr) && (gestalt_temp&(1<<gestaltStandardFile58)));
  89.     
  90.         isHuman=Gestalt(gestaltPowerMgrAttr, &gestalt_temp);
  91.         gHasPowerManager=((!isHuman) && (gestalt_temp&(1<<gestaltPMgrCPUIdle)));
  92.         
  93.         isHuman=Gestalt(gestaltNotificationMgrAttr, &gestalt_temp);
  94.         gHasNotificationManager=(!((isHuman) ||
  95.             (((gestalt_temp >> gestaltNotificationPresent) & 0x01) != 1)));
  96.         
  97.         isHuman=Gestalt(gestaltAppleEventsAttr, &gestalt_temp);
  98.         gHasAppleEvents=((!isHuman) && (gestalt_temp&(1<<gestaltAppleEventsPresent)));
  99.     }
  100.     else
  101.     {
  102.         gHasColorQD=theWorld.hasColorQD;
  103.         gSystemSevenOrLater=(theWorld.systemVersion>=1792);
  104.         gHasFSSpecs=TrapAvailable(_HFSPinaforeDispatch);
  105.         gStandardFile58=gSystemSevenOrLater;
  106.         gHasPowerManager=TrapAvailable(0xA285);    /* _IdleUpdate */
  107.         gHasNotificationManager=TrapAvailable(_NMInstall);
  108.         gHasAppleEvents=TrapAvailable(_Pack8);
  109.     }
  110.     
  111.     if (gHasAppleEvents)
  112.         SetUpAppleEvents();        /* see apple events.c */
  113.     
  114.     gForegroundWaitTime=30;            /* WaitNextEvent sleep time when we're in frgrnd */
  115.     gBackgroundWaitTime=100;        /* WaitNextEvent sleep time when we're in bkgrnd */
  116.     gDone=FALSE;                    /* TRUE if program is done (exit event loop) */
  117.     gInProgress=FALSE;                /* TRUE if progress bar is up */
  118.     gIsInBackground=FALSE;            /* TRUE if program is in background */
  119.     gPendingResultCode=allsWell;    /* set to error code if error occurs while in bkgrnd */
  120.     
  121.     return TRUE;
  122. }
  123.